﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using OpenSoftStore.Orm;
using OpenSoftStore.Orm.Model;

namespace OpenSoftStore.BusinessLogic
{
    public abstract class ABusinessLogic
    {
        #region Fields

        public SpaEntities Spa;

        #endregion

        #region Constructors

        public ABusinessLogic()
        {
            Spa = new SpaEntities();
        }

        #endregion     

        #region Methods

        public int Add(Object o)
        {
            return Spa.Add(o);
        }

        public int Delete(Object o)
        {
            return Spa.Delete(o);
        }

        public int Update(Object o)
        {
            return Spa.Update(o);
        }

        public IEnumerable<TEntity> Where<TEntity>(Expression<Func<TEntity, bool>> func) where TEntity : new()
        {
            return Spa.Where<TEntity>(func);
        }

        public IEnumerable<TEntity> SqlWhere<TEntity>(string strWhere) where TEntity : new()
        {
            return Spa.Where<TEntity>(strWhere);
        }

        public IEnumerable<TEntity> SelectWhere<TEntity>(string strSqlQuery) where TEntity : new()
        {
            return Spa.SelectWhere<TEntity>(strSqlQuery);
        }

        public DataSet RunSqLcmdDataSet(string sql)
        {
            return Spa.RunSqLcmdDataSet(sql);
        }

        public string GetCountNo(string tableName, Boolean isDatatime = false, string where="",int lenght=6)
        {
            return Spa.GetCountNo(tableName, isDatatime, where, lenght);
        }

        #endregion

    }
}
